# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Gabriel Magno <gabrielmagno1@gmail.com>
# Contributor: Michał Pałubicki <maln0ir@gmx.com>

_pyname=agate
pkgname=python-$_pyname
pkgver=1.9.0
pkgrel=1
pkgdesc='A data analysis library that is optimized for humans instead of machines'
arch=(any)
url='https://agate.readthedocs.org/'
license=(MIT)
_pydeps=(babel
         isodate
         leather
         parsedatetime
         pyicu
         pytimeparse
         six
         slugify
         sphinx_rtd_theme
         sphinx-furo)
depends=(python "${_pydeps[@]/#/python-}")
makedepends=(python-setuptools
             python-sphinx)
checkdepends=(python-cssselect
              python-lxml
              python-nose)
_archive="$_pyname-$pkgver"
source=("https://files.pythonhosted.org/packages/source/${_pyname::1}/$_pyname/$_archive.tar.gz")
sha256sums=('901b65382da982cfb52912246fb0ff3457d3ac02b94fafd4b10b0bff3ec358c5')

prepare() {
	cd "$_archive"
	# Note: Upstream test suite is currently badly broken; it depends on the
	# system local and fails on some. Part of the trouble is tracable to
	# parsedatetime bugs so they limit allowed versions. We're going to skip
	# known problematic tests to allow Arch's packaged version.
	sed -i -e "/parsedatetime/s/>.*'/'/" setup.py
}

build() {
	cd "$_archive"
	python setup.py build
	make -C docs html
	_rtd_theme_path="$(python -c 'import sphinx_rtd_theme; print(sphinx_rtd_theme.get_html_theme_path())')"
	rm -rvf "docs/_build/html/_static"
	ln -svf "$_rtd_theme_path/sphinx_rtd_theme/static" "docs/_build/html/_static"
}

check() {
	cd "$_archive"
	LC_ALL=POSIX nosetests --exclude=test_cast_format_locale
}

package() {
	cd "$_archive"
	python setup.py install --root="$pkgdir" --optimize=1 --skip-build
	mkdir -p "$pkgdir/usr/share/doc"
	cp -rv "docs/_build/html" "$pkgdir/usr/share/doc/$pkgname"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" COPYING
}
